package com.dyxs.read.wxapi;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;

import com.songcha.library_business.event.wx.WXPayRespEvent;
import com.songcha.library_business.helper.WxHelper;
import com.tencent.mm.opensdk.modelbase.BaseReq;
import com.tencent.mm.opensdk.modelbase.BaseResp;
import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler;


import org.greenrobot.eventbus.EventBus;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

public class WXPayEntryActivity extends AppCompatActivity implements IWXAPIEventHandler {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        WxHelper.getWxApi().handleIntent(getIntent(), this);
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        setIntent(intent);
        WxHelper.getWxApi().handleIntent(intent, this);
    }

    @Override
    public void onReq(BaseReq req) {
        Log.i("onReq",req.toString());
    }

    @Override
    public void onResp(BaseResp resp) {
        Log.i("onResp",resp.toString()+","+resp.getType()+","+resp.errCode);
        if(resp.getType()==5){//pay type
            if(resp.errCode==0){
                //pay success
            }else if(resp.errCode==-2){
                //pay cancel
            }else{
                //pay error
            }
            EventBus.getDefault().post(new WXPayRespEvent(resp.errCode));
        }
        finish();
    }
}



